<template>
  <div class="popule">
    <van-field
      v-model="content"
      rows="2"
      autosize
      type="textarea"
      maxlength="50"
      placeholder="请输入留言"
      show-word-limit
    />
    <van-button @click="putComment" class="btn-info">发布</van-button>
  </div>
</template>

<script>
import { putCommentAPI } from '@/api'
export default {
  name: '',
  components: {},
  props: {
    articleInfo: {
      type: Object,
      required: true
    },
    art_id: {
      type: [Number, String],
      required: true
    },
    isReply: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      // 文本内容
      content: ''
    }
  },
  computed: {},
  watch: {},
  created() {},
  methods: {
    async putComment() {
      if (this.content.trim() === '') {
        return this.$toast.fail('评论内容不能为空')
      }
      try {
        const { data } = await putCommentAPI({
          target: this.isReply
            ? this.articleInfo.art_id
            : this.articleInfo.com_id,
          content: this.content,
          art_id: this.art_id
        })
        this.$emit('update-list', data.data.new_obj)
        this.$emit('updata-popu')
        this.content = ''
        this.$toast.fail('发布成功')
      } catch (error) {
        this.$toast.fail('发布失败')
      }
    }
  }
}
</script>

<style scoped lang="less">
.popule {
  background-color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
}
.btn-info {
  border: unset;
  color: #6ba3d8;
  width: 2rem;
  font-size: 0.37333rem;
}
</style>
